<?php

// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 订单商品生产表查询类
 * @package  module/base/bill
 * @author   create by allen.qiang
 * @version 1.0
 */

 class billGoodsProduct{

     /**
      * 根据配送站分组查询订单商品生产信息
      * @param array $arg_array
      * @return null|array
      */
     public function searchbillGoodsProductGroup( &$arg_array ) {

         global $G_SHOP;

         //sql字符串
         $sql = '';

         //参数类型字符串
         $params_type = '';

         //参数值数组
         $params_array = array();

         //订单号
         if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
             $sql .= ' AND bill_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_no'];
         }

         //订单编号
         if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
             $sql .= ' AND bill_code = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_code'];
         }

         //订单商品流水号
         if (isset($arg_array['bill_goods_no']) &&  !empty($arg_array['bill_goods_no'])) {
             $sql .= ' AND bill_goods_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_goods_no'];
         }

         //城市ID
         if (isset($arg_array['cityID']) && is_numeric($arg_array['cityID'])) {
             $sql .= ' AND cityID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['cityID'];
         }

         //订单类型
         if (isset($arg_array['billType']) && in_array($_REQUEST['billType'],array(1,2,3,4,5,6,7,8,9))) {
             $sql .= ' AND billType = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['billType'];
         }

         //配送日期
         if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
             $sql .= ' AND send_date = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['send_date'];
         }

         //配送开始时间
         if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
             $sql .= ' AND send_start_time >= ?';
             $params_type .= 's';
             $params_array[] = $arg_array['send_start_time'];
         }

         //配送结束时间
         if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
             $sql .= ' AND send_start_time <= ?  ';
             $params_type .= 's';
             $params_array[] = $arg_array['send_start_time_end'];
         }

         //配送站ID
         if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
             $sql .= ' AND distribution_id = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['distribution_id'];
         }

         //配送站名称
         if (isset($arg_array['distribution_name']) && !empty($arg_array['distribution_name'])) {
             $sql .= ' AND distribution_name = ?';
             $params_type .= 's';
             $params_array[] = encryptD($arg_array['distribution_name']);
         }

         //加急状态
         if (isset($arg_array['is_urgent']) && is_numeric($arg_array['is_urgent'])) {
             $sql .= ' AND is_urgent = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_urgent'];
         }

         //网购号
         if (isset($_REQUEST['goods_postID']) && is_numeric($arg_array['goods_postID'])) {
             $sql .= ' AND goods_postID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['goods_postID'];
         }


         //商家编码
         if (isset($arg_array['product_code']) && !empty($arg_array['product_code'])) {
             $sql .= ' AND product_code = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['product_code'];
         }

         //商品名称 /SKU / 商品ID  模糊查询
         if (isset($arg_array['sku']) && !empty($arg_array['sku'])) {
             $sql .= ' AND (goods_name like ? OR product_code =? OR goods_postID = ?) ';
             $params_type .= 'ssi';
             $params_array[] = '%'.$arg_array['sku'].'%';
             $params_array[] = $arg_array['sku'];
             $params_array[] = $arg_array['sku'];
         }

         //商品规格
         if (isset($arg_array['goods_spec']) && !empty($arg_array['goods_spec'])) {
             $sql .= ' AND goods_spec = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['goods_spec'];
         }

         //商品数量
         if (isset($arg_array['goods_amount']) && is_numeric($arg_array['goods_amount'])) {
             $sql .= ' AND goods_amount = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['goods_amount'];
         }

         //餐具数量
         if (isset($arg_array['tableware_amount']) && is_numeric($arg_array['tableware_amount'])) {
             $sql .= ' AND tableware_amount = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['tableware_amount'];
         }

         //生日牌
         if (isset($arg_array['birthday_card']) && !empty($arg_array['birthday_card'])) {
             if($arg_array['birthday_card'] == 1){ //状态为是 含生日牌
                 $sql .= ' AND birthday_card IS NOT NULL AND birthday_card <> "" ';
             }else{
                 $sql .= ' AND birthday_card = "" ';
             }
         }

         //切分状态
         if (isset($arg_array['segmentation']) && is_numeric($arg_array['segmentation'])) {
             if($arg_array['segmentation'] == 1){ //状态为是 切分
                 $sql .= ' AND segmentation >= ?';
             }else{
                 $sql .= ' AND segmentation = ?';
             }
             $params_type .= 'i';
             $params_array[] = $arg_array['segmentation'];

         }

         //生产状态
         if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
             $sql .= ' AND print_num > ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['print_num'];
         }

         //入库状态
         if (isset($arg_array['is_voucher']) && is_numeric($arg_array['is_voucher'])) {
             $sql .= ' AND is_voucher = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_voucher'];
         }

         //上车状态
         if (isset($arg_array['is_warehouse']) && is_numeric($arg_array['is_warehouse'])) {
             $sql .= ' AND is_warehouse = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_warehouse'];
         }

         //下车状态
         if (isset($arg_array['is_busScan']) && is_numeric($arg_array['is_busScan'])) {
             $sql .= ' AND is_busScan = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_busScan'];
         }

         //拓展字段
         if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
             $sql .= $arg_array['extend'];
         }

         //add by sunqiang 下午茶订单不走生产 该模块需重新规划 start
         $sql .= ' AND bill_no NOT IN (select bill_no from bill_master where billPlatform = 3)  ';

         //add by sunqiang 下午茶订单不走生产 该模块需重新规划　end

         //add by allen.qiang 20141104 FUN-BK-0014 代付单跳流程 ---start
         if (isset($arg_array['G_DFD_SKU']) && !empty($arg_array['G_DFD_SKU']) && $arg_array['G_DFD_SKU']=="DFD") { //是不是代付单跳流程查询
             $sql .= " AND product_code NOT IN (".G_TPT_SKU.")";//排除代付单的特殊商品编码
         }
         //add by allen.qiang 20141104 FUN-BK-0014 代付单跳流程 ---end




         //通过配送站分组查询订单商品生产表
         if ( $sql ) {
             $sql = ' WHERE ' . substr($sql, 4) .' GROUP BY distribution_id ';
         }

         //查询分类信息
         $search_sql = 'SELECT send_date,distribution_name,
             COUNT(*) AS bill_goods_num,
             SUM(IF(print_num > 0, 1, 0)) AS print_num,
             SUM(is_voucher) AS voucher_num,
             distribution_id,
             SUM(is_warehouse ) AS warehouse_num,
             SUM(is_busScan ) AS busScan_num,
             SUM(is_packScan ) AS packScan_num
             FROM bill_goods_product' . $sql;

         $temp_item_array = $G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);


         if (!$temp_item_array) {
             return null;
         }

         foreach ($temp_item_array as $bill) {
             $item_array[] = array(
                 'send_date' => $bill->send_date,
                 'distribution_name'=>$bill->distribution_name,
                 'bill_goods_num'=>$bill->bill_goods_num,
                 'print_num'=>$bill->print_num,
                 'voucher_num'=>$bill->voucher_num,
                 'distribution_id' => $bill->distribution_id,
                 'warehouse_num'=>$bill->warehouse_num,
                 'busScan_num'=>$bill->busScan_num,
                 'packScan_num'=>$bill->packScan_num  //已装包蛋糕数量 add by allen.qiang 2015-06-10
             );
         }

         return $item_array;

     }


     /**
      * 订单商品生产表 bill_goods_product
      * @param array $arg_array
      * @return null|array
      */
     public function searchBillGoodsInfo( &$arg_array ) {

         global $G_SHOP;

         //sql字符串
         $sql = '';

         //参数类型字符串
         $params_type = '';

         //参数值数组
         $params_array = array();

         //订单号
         if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
             $sql .= ' AND bill_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_no'];
         }

         //订单编号
         if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
             $sql .= ' AND bill_code = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_code'];
         }

         //订单商品流水号
         if (isset($arg_array['bill_goods_no']) &&  !empty($arg_array['bill_goods_no'])) {
             $sql .= ' AND bill_goods_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_goods_no'];
         }

         //城市ID
         if (isset($arg_array['cityID']) && is_numeric($arg_array['cityID'])) {
             $sql .= ' AND cityID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['cityID'];
         }

         //订单类型
         if (isset($arg_array['billType']) && in_array($_REQUEST['billType'],array(1,2,3,4,5,6,7,8,9))) {
             $sql .= ' AND billType = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['billType'];
         }

         //配送日期
         if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
             $sql .= ' AND send_date = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['send_date'];
         }

         //配送开始时间
         if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
             $sql .= ' AND send_start_time >= ?';
             $params_type .= 's';
             $params_array[] = $arg_array['send_start_time'];
         }

         //配送结束时间
         if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
             $sql .= ' AND send_start_time <= ?  ';
             $params_type .= 's';
             $params_array[] = $arg_array['send_start_time_end'];
         }

         //配送站ID
         if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
             $sql .= ' AND distribution_id = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['distribution_id'];
         }

         //配送站名称
         if (isset($arg_array['distribution_name']) && !empty($arg_array['distribution_name'])) {
             $sql .= ' AND distribution_name = ?';
             $params_type .= 's';
             $params_array[] = encryptD($arg_array['distribution_name']);
         }

         //加急状态
         if (isset($arg_array['is_urgent']) && is_numeric($arg_array['is_urgent'])) {
             $sql .= ' AND is_urgent = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_urgent'];
         }

         //网购号
         if (isset($_REQUEST['goods_postID']) && is_numeric($arg_array['goods_postID'])) {
             $sql .= ' AND goods_postID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['goods_postID'];
         }


         //商家编码
         if (isset($arg_array['product_code']) && !empty($arg_array['product_code'])) {
             $sql .= ' AND product_code = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['product_code'];
         }

         //商品名称 /SKU / 商品ID  模糊查询
         if (isset($arg_array['sku']) && !empty($arg_array['sku'])) {
             $sql .= ' AND (goods_name like ? OR product_code =? OR goods_postID = ?) ';
             $params_type .= 'ssi';
             $params_array[] = '%'.$arg_array['sku'].'%';
             $params_array[] = $arg_array['sku'];
             $params_array[] = $arg_array['sku'];
         }

         //商品规格
         if (isset($arg_array['goods_spec']) && !empty($arg_array['goods_spec'])) {
             $sql .= ' AND goods_spec = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['goods_spec'];
         }

         //商品数量
         if (isset($arg_array['goods_amount']) && is_numeric($arg_array['goods_amount'])) {
             $sql .= ' AND goods_amount = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['goods_amount'];
         }

         //餐具数量
         if (isset($arg_array['tableware_amount']) && is_numeric($arg_array['tableware_amount'])) {
             $sql .= ' AND tableware_amount = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['tableware_amount'];
         }

         //生日牌
         if (isset($arg_array['birthday_card']) && !empty($arg_array['birthday_card'])) {
             if($arg_array['birthday_card'] == 1){ //状态为是 含生日牌
                 $sql .= ' AND birthday_card IS NOT NULL';
             }else{
                 $sql .= ' AND birthday_card IS NULL';
             }
         }

         //切分状态
         if (isset($arg_array['segmentation']) && is_numeric($arg_array['segmentation'])) {
             if($arg_array['segmentation'] == 1){ //状态为是 切分
                 $sql .= ' AND segmentation >= ?';
             }else{
                 $sql .= ' AND segmentation = ?';
             }
             $params_type .= 'i';
             $params_array[] = $arg_array['segmentation'];

         }

         //是否打印
         if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
             if($arg_array['print_num'] == 1){ //状态为是 打印
                 $sql .= ' AND print_num >= ?';
             }else{
                 $sql .= ' AND print_num = ?';
             }
             $params_type .= 'i';
             $params_array[] = $arg_array['print_num'];

         }

         //入库状态
         if (isset($arg_array['is_voucher']) && is_numeric($arg_array['is_voucher'])) {
             $sql .= ' AND is_voucher = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_voucher'];
         }

         //上车状态
         if (isset($arg_array['is_warehouse']) && is_numeric($arg_array['is_warehouse'])) {
             $sql .= ' AND is_warehouse = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_warehouse'];
         }

         //下车状态
         if (isset($arg_array['is_busScan']) && is_numeric($arg_array['is_busScan'])) {
             $sql .= ' AND is_busScan = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['is_busScan'];
         }

         //拓展字段
         if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
             $sql .= $arg_array['extend'];
         }


         //add by sunqiang 下午茶订单不走生产 该模块需重新规划 start
         $sql .= ' AND bill_no NOT IN (select bill_no from bill_master where billPlatform = 3)  ';

         //add by sunqiang 下午茶订单不走生产 该模块需重新规划　end



         //add by allen.qiang 20141226 FUN-BK-0014 代付单跳流程-质检入库、上车扫描、下车扫描隐藏特殊商品 ---start
         if (isset($arg_array['G_DFD_SKU']) && !empty($arg_array['G_DFD_SKU']) && $arg_array['G_DFD_SKU']=="DFD") { //是不是代付单跳流程查询
             $sql .= " AND product_code NOT IN (".G_TPT_SKU.")";//排除代付单的特殊商品编码
         }
         //add by allen.qiang 20141226 FUN-BK-0014 代付单跳流程-质检入库、上车扫描、下车扫描隐藏特殊商品 ---end

         if ($sql) {
             $sql = ' WHERE ' . substr($sql, 4);
         }

         try {

             if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                 //统计数量
                 $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_goods_product ' . $sql;

                 $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);


                 $item_count = $count_array[0]->item_count;
                 if ($item_count == 0) {
                     $arg_array['count'] = 0;
                     return null;
                 }

                 $arg_array['count'] = $item_count;

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                 //分页
                 if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                     $arg_array['page'] = 1;

                 $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

             } else {

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

             }

             //查询分类信息
             //mod by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -start
             // $search_sql = 'SELECT * FROM bill_goods_product' . $sql;
             $search_sql = 'SELECT bill_goods_product.*, (select distribution_technicia from bill_master where bill_code = bill_goods_product.bill_code) AS distribution_technicia FROM bill_goods_product' . $sql;
             //mod by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -end
             $temp_item_array = $G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);


             if (!$temp_item_array) {
                 return null;
             }

             foreach ($temp_item_array as $bill) {

                 //订单类型
                 switch ($bill->billType) {
                     case '1':
                         $billType = "正常订单";
                         break;
                     case '2':
                         $billType = "生日会蛋糕";
                         break;
                     case '3':
                         $billType = "市场推广";
                         break;
                     case '4':
                         $billType = "其他订单";
                         break;
                     case '5':
                         $billType = "补偿订单";
                         break;
                     case '6':
                         $billType = "测试订单";
                         break;
                     case '7':
                         $billType = "招待赠送";
                         break;
                     case '8':
                         $billType = "大客户订单";
                         break;
                     case '9':
                         $billType = "试吃订单";
                         break;
                 }

                 $item_array[] = array(

                     'uuid' => $bill->uuid,
                     'creator' => $bill->creator,
                     'createTime' => $bill->createTime,
                     'bill_no' => (string)$bill->bill_no,
                     'bill_code' => (string)$bill->bill_code,
                     //add by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -start
                     'distribution_technicia' => $bill->distribution_technicia,
                     //add by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -end
                     'bill_goods_no' => (string)$bill->bill_goods_no,
                     'cityID' => $bill->cityID,
                     'cityName' => $bill->cityName,
                     'billType' => $billType,
                     'send_date' => $bill->send_date,
                     'send_start_time' => $bill->send_start_time,
                     'send_end_time' => $bill->send_end_time,
                     'distribution_id' => $bill->distribution_id,
                     'distribution_name' => $bill->distribution_name,
                     'is_urgent' => $bill->is_urgent,
                     'goods_postID' => $bill->goods_postID,
                     'product_code' => $bill->product_code,
                     'goods_name' => $bill->goods_name,
                     'goods_spec' => $bill->goods_spec,
                     'goods_amount' => $bill->goods_amount,

                     'tableware_amount' => $bill->tableware_amount,
                     'extra_tableware_amount'=>$bill->extra_tableware_amount,
                     'candle_amount'=>$bill->candle_amount,
                     'extra_candle_amount'=>$bill->extra_candle_amount,

                     'birthday_card' => $bill->birthday_card,
                     'segmentation' => $bill->segmentation,
                     'goods_remark' => $bill->goods_remark,
                     'print_num' => $bill->print_num,
                     'print_operator' => $bill->print_operator,
                     'print_time' => $bill->print_time,
                     'is_voucher' =>$bill->is_voucher,
                     'voucher_operator'=>$bill->voucher_operator,
                     'voucher_time'=>$bill->voucher_time,
                     'is_warehouse' =>$bill->is_warehouse,
                     'warehouse_operator'=>$bill->warehouse_operator,
                     'warehouse_time'=>$bill->warehouse_time,
                     'is_busScan' =>$bill->is_busScan,
                     'busScan_operator'=>$bill->busScan_operator,
                     'busScan_time'=>$bill->busScan_time,
                     'is_packScan'=>$bill->is_packScan,
                     'packScan_operator'=>$bill->packScan_operator,
                     'packScan_time'=>$bill->busScan_time,
                     'busScan_time'=>$bill->busScan_time,
                 );
             }

             return $item_array;

         } catch (Exception $e) {

             error_log($e->getMessage());
             return null;
         }

     }


     /**
      * 查询订单商品表信息bill_goods
      * @param array $arg_array
      * @return null|array
      */
     public function searchBillGoods( &$arg_array ) {

         global $G_PGLOB;

         //sql字符串
         $sql = '';

         //参数类型字符串
         $params_type = '';

         //参数值数组
         $params_array = array();

         //订单号
         if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
             $sql .= ' AND bill_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_no'];
         }

         //订单编号后六位
         if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
             $sql .= ' AND bill_code LIKE ? ';
             $params_type .= 's';
             $params_array[] = '%'.$arg_array['bill_code']. '%';
         }

         //订单商品流水号
         if (isset($arg_array['bill_goods_no']) &&  !empty($arg_array['bill_goods_no'])) {
             $sql .= ' AND bill_goods_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_goods_no'];
         }

         //城市ID
         if (isset($arg_array['cityID']) && is_numeric($arg_array['cityID'])) {
             $sql .= ' AND cityID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['cityID'];
         }

         //订单类型
         if(isset($arg_array['bill_type']) && !empty($arg_array['bill_type'])){
             if(strpos($arg_array['bill_type'],'all') !== false){
                 $sql .= " AND billType IN (1,2,3,4,5,6,7,8,9)";
             }else{
                 $sql .= " AND billType IN ( ".$arg_array['bill_type']." )";
             }
         }

         //拓展字段
         if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
             $sql .= $arg_array['extend'];
         }

         if ($sql) {
             $sql = ' WHERE ' . substr($sql, 4);
         }

         try {

             if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                 //统计数量
                 $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_goods' . $sql;

                 $count_array = &$G_PGLOB->DBCA->stmt_query($search_sql, $params_type, $params_array);


                 $item_count = $count_array[0]->item_count;
                 if ($item_count == 0) {
                     $arg_array['count'] = 0;
                     return null;
                 }

                 $arg_array['count'] = $item_count;

                 if($_REQUEST['count'] < $_REQUEST['rp']){
                     $_REQUEST['page'] = 1;
                 }

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                 //分页
                 if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                     $arg_array['page'] = 1;

                 $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

             } else {

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

             }

             //查询分类信息
             $search_sql = 'SELECT * FROM bill_goods' . $sql;
             $temp_item_array = $G_PGLOB->DBCA->stmt_query($search_sql, $params_type, $params_array);

             if (!$temp_item_array) {
                 return null;
             }

             foreach ($temp_item_array as $item) {


                 $item_array[] = array(

                     'bill_no' => (string)$item->bill_no,
                     'bill_goods_no' => (string)$item->bill_goods_no,
                     'goods_goodsID' => $item->goods_goodsID,
                     'goods_postID' => $item->goods_postID,
                     'product_code' => $item->product_code,
                     'goods_name' => $item->goods_name,
                     'goods_spec' => $item->goods_spec,
                     'goods_amount' => $item->goods_amount,
                     'goods_marketPrice' => $item->goods_marketPrice,
                     'goods_storePrice' => $item->goods_storePrice,
                     'goods_purchasePrice' => $item->goods_purchasePrice,
                     'goods_points' => $item->goods_points,
                     'goods_weight' => $item->goods_weight,
                     'goods_from' => $item->goods_from,
                     'goods_groupID' => $item->goods_groupID,
                     'goods_status' => $item->goods_status,
                     'goods_time' => $item->goods_time,
                     'goods_delivercount' => $item->goods_delivercount,
                     'goods_withdrawAmount' => $item->goods_withdrawAmount,
                     'goods_rejectionAmount' => $item->goods_rejectionAmount,
                     'goods_pointsPrice' => $item->goods_pointsPrice,
                     'extra_tableware_amount' => $item->extra_tableware_amount,
                     'extra_candle_amount' => $item->extra_candle_amount,
                     'candle_amount' => $item->candle_amount,
                     'comment_flg' => $item->comment_flg,
                     'product_amount' => $item->product_amount,
                     'birthday_card' => $item->birthday_card,
                     'segmentation' => $item->segmentation,
                     'candle' => $item->candle,
                     'goods_remark' => $item->goods_remark,
                     'tableware_amount' => $item->tableware_amount,
                     'print_num' => $item->print_num,
                     'print_operator' => $item->print_operator,
                     'print_time' => $item->print_time,
                     'is_voucher' => $item->is_voucher,
                     'voucher_operator' => $item->voucher_operator,
                     'voucher_time' => $item->voucher_time,
                     'is_warehouse' => $item->is_warehouse,
                     'warehouse_operator' => $item->warehouse_operator,
                     'warehouse_time' => $item->warehouse_time,
                     'is_busScan' => $item->is_busScan,
                     'busScan_operator' => $item->busScan_operator,
                     'busScan_time' => $item->busScan_time,
                     'auth_alter' => $item->auth_alter
                 );
             }

             return $item_array;

         } catch (Exception $e) {

             error_log($e->getMessage());
             return null;
         }

     }


     /**
      * 查询漏操作订单商品表信息bill_goods_operate_forget
      * @param array $arg_array
      * @return null|array
      */
     public function searchBillGoodsOperateForget( &$arg_array ) {

         global $G_PGLOB;

         //sql字符串
         $sql = '';

         //参数类型字符串
         $params_type = '';

         //参数值数组
         $params_array = array();

         //订单号
         if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
             $sql .= ' AND bill_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_no'];
         }

         //订单编号
         if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
             $sql .= ' AND bill_code LIKE ? ';
             $params_type .= 's';
             $params_array[] = '%'.$arg_array['bill_code']. '%';
         }

         //订单商品流水号
         if (isset($arg_array['bill_goods_no']) &&  !empty($arg_array['bill_goods_no'])) {
             $sql .= ' AND bill_goods_no = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['bill_goods_no'];
         }

         //城市ID
         if (isset($arg_array['cityID']) && is_numeric($arg_array['cityID'])) {
             $sql .= ' AND cityID = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['cityID'];
         }

         //配送日期
         if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
             $sql .= ' AND send_date = ?';
             $params_type .= 's';
             $params_array[] = $arg_array['send_date'];
         }

         //配送站ID
         if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
             $sql .= ' AND distribution_id = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['distribution_id'];
         }

         //配送站名称
         if (isset($arg_array['distribution_name']) && !empty($arg_array['distribution_name'])) {
             $sql .= ' AND distribution_name = ?';
             $params_type .= 's';
             $params_array[] = encryptD($arg_array['distribution_name']);
         }

         //漏操作名称
         if (isset($arg_array['forget_operate_flow']) && is_numeric($arg_array['forget_operate_flow'])) {
             $sql .= ' AND forget_operate_flow = ?';
             $params_type .= 'i';
             $params_array[] = $arg_array['forget_operate_flow'];
         }

         //拓展字段
         if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
             $sql .= $arg_array['extend'];
         }

         if ($sql) {
             $sql = ' WHERE ' . substr($sql, 4);
         }

         try {

             if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                 //统计数量
                 $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_goods_operate_forget' . $sql;

                 $count_array = &$G_PGLOB->DBCA->stmt_query($search_sql, $params_type, $params_array);


                 $item_count = $count_array[0]->item_count;
                 if ($item_count == 0) {
                     $arg_array['count'] = 0;
                     return null;
                 }

                 $arg_array['count'] = $item_count;

                 if($_REQUEST['count'] < $_REQUEST['rp']){
                     $_REQUEST['page'] = 1;
                 }

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                 //分页
                 if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                     $arg_array['page'] = 1;

                 $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

             } else {

                 //排序
                 if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                     $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

             }

             //查询分类信息
             $search_sql = 'SELECT * FROM bill_goods_operate_forget ' . $sql;

             $temp_item_array = $G_PGLOB->DBCA->stmt_query($search_sql, $params_type, $params_array);

             if (!$temp_item_array) {
                 return null;
             }

             foreach ($temp_item_array as $bill) {

                 $item_array[] = array(

                     'uuid' => $bill->uuid,
                     'creator' => $bill->creator,
                     'createTime' => $bill->createTime,
                     'bill_no' => (string)$bill->bill_no,
                     'bill_code' => (string)$bill->bill_code,
                     'bill_goods_no' => (string)$bill->bill_goods_no,
                     'cityID' => $bill->cityID,
                     'cityName' => $bill->cityName,
                     'billType' => $bill->billType,
                     'bill_status' => $bill->bill_status,
                     'send_date' => $bill->send_date,
                     'send_start_time' => $bill->send_start_time,
                     'send_end_time' => $bill->send_end_time,
                     'distribution_id' => $bill->distribution_id,
                     'distribution_name' => $bill->distribution_name,
                     'is_urgent' => $bill->is_urgent,
                     'goods_postID' => $bill->goods_postID,
                     'product_code' => $bill->product_code,
                     'goods_name' => $bill->goods_name,
                     'goods_spec' => $bill->goods_spec,
                     'goods_amount' => $bill->goods_amount,

                     'tableware_amount' => $bill->tableware_amount,
                     'extra_tableware_amount'=>$bill->extra_tableware_amount,
                     'candle_amount'=>$bill->candle_amount,
                     'extra_candle_amount'=>$bill->extra_candle_amount,

                     'birthday_card' => $bill->birthday_card,
                     'segmentation' => $bill->segmentation,
                     'goods_remark' => $bill->goods_remark,
                     'print_num' => $bill->print_num,
                     'print_operator' => $bill->print_operator,
                     'print_time' => $bill->print_time,
                     'operate_record'=>$bill->operate_record,
                     'forget_operate_flow'=>$bill->forget_operate_flow,
                     'forget_check_operator'=>$bill->forget_check_operator,
                     'forget_check_operate_time'=>$bill->forget_check_operate_time

                 );
             }

             return $item_array;

         } catch (Exception $e) {

             error_log($e->getMessage());
             return null;
         }

     }
 }
